package com.yanzhu.service.impl;

import com.yanzhu.service.CommentService;
import com.yanzhu.service.mapper.CommentMapper;
import com.yanzhu.service.mapper.MessageMapper;
import com.yanzhu.service.model.Comment;
import com.yanzhu.service.model.Message;
import com.yanzhu.service.model.mix.VideoComment;
import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: 方炎柱
 * @Description:
 * @Date: Created in 9:43 2018/1/24
 * @Modified:
 */
@AllArgsConstructor
@Service
public class CommentServiceImpl implements CommentService {
    private CommentMapper commentMapper;

    private MessageMapper messageMapper;

    @Override
    public int insert(Comment comment) {
        return commentMapper.insert(comment);
    }

    @Override
    @Transactional
    public void commentVideo(Comment comment, Message message) {
        commentMapper.insert(comment);
        messageMapper.insert(message);
    }

    @Override
    public List<VideoComment> queryCommentList(long vid, int page, int size) {
        int begin = (page - 1) * size;
        return commentMapper.queryCommentList(vid, begin,  size);
    }

    @Override
    public int deleteCommentById(long id) {
        return commentMapper.deleteCommentById(id);
    }

    @Override
    public int deleteCommentAll(long uid, long vid) {
        return commentMapper.deleteCommentAll(uid, vid);
    }
}
